package com.service.impl;

import com.czbspringmvc.annotation.Service;
import com.entity.Monster;
import com.service.MonsterService;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: 陈正彬
 * 作为service注入到spring容器
 */
@Service
public class MonsterServiceImpl implements MonsterService {
    @Override
    public List<Monster> listMonster() {
        //模拟一个数据当DB
        List<Monster> monster = new ArrayList<>();
        monster.add(new Monster(100,"孙悟空","七十二变",1000));
        monster.add(new Monster(200,"猪八戒","三十六变",900));
        return monster;
    }

    @Override
    public List<Monster> findMonsterByName(String name) {
        //模拟一个数据当DB
        List<Monster> monster = new ArrayList<>();
        monster.add(new Monster(100,"孙悟空","七十二变",1000));
        monster.add(new Monster(200,"猪八戒","三十六变",900));
        monster.add(new Monster(300,"唐僧","念经",90));
        monster.add(new Monster(400,"沙悟净","禅杖",800));
        monster.add(new Monster(500,"白龙马","会飞",550));

        //创建集合返回查询到的monster集合
        List<Monster> findMonster = new ArrayList<>();
        //遍历monster集合，返回满足条件的
        for (Monster monster1 : monster) {
            if (monster1.getName().contains(name)){
                findMonster.add(monster1);
            }
        }
        return findMonster;
    }

    @Override
    public boolean login(String name) {
        //这里模拟DB，如果是孙悟空就登入成功
        if ("孙悟空".equals(name)) {
            return true;
        } else {
            return false;
        }
    }
}
